//
//  NYSearchTableHeadView.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/8.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYSearchTableHeadView.h"
#import "NYSearchHotModel.h"
@interface NYSearchTableHeadView ()

@property (nonatomic, weak) id<NYSearchTableHeadViewDelegate> delegate;

@property (nonatomic, strong) UILabel *hotLabel;
@property (nonatomic, strong) QMUIFloatLayoutView *floatLayoutView;

@property (nonatomic, copy) NYSearchHotBlock hotBlock;
@end

@implementation NYSearchTableHeadView


- (instancetype)initWithDelegate:(id<NYSearchTableHeadViewDelegate>)delegate
                  requestSuccess:(void(^)(void))success {
        
    self = [super initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 35)];
    if (self) {
        
        self.hotBlock = success;
        self.delegate = delegate;
        [self initUI];
    }
    return self;
}
#pragma mark - Intial Methods
- (void)initUI {
    
    self.backgroundColor = UIColorMakeWithHex(@"#F3F4F5");
    [self addSubview:self.hotLabel];
    [self addSubview:self.floatLayoutView];

    [self.hotLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self).offset(20);
        make.height.mas_equalTo(15);
        make.left.equalTo(self).offset(15);
        make.width.mas_equalTo(200);
    }];
    
    
    NSArray<NSString *> *suggestions = @[@"新概念", @"托福基础班", @"考研", @"口译", @"精讲精练", @"雅思", @"小语种"];
    for (NSInteger i = 0; i < suggestions.count; i++) {
        QMUIGhostButton *button = [[QMUIGhostButton alloc] init];
        button.ghostColor = UIColorMakeWithHex(@"#333333");;
        [button setTitle:suggestions[i] forState:UIControlStateNormal];
        button.titleLabel.font = UIFontMake(13);
        button.contentEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10);
        [button setTitleColor:UIColorMakeWithHex(@"#D0D0D0") forState:0];
        [button setBackgroundColor:UIColorMakeWithHex(@"#EBEBEB")];
        button.borderWidth = 0.f;
        [self.floatLayoutView addSubview:button];
    }

    CGFloat contentWidth = SCREEN_WIDTH;
    CGSize floatLayoutViewSize = [self.floatLayoutView sizeThatFits:CGSizeMake(contentWidth, CGFLOAT_MAX)];
    self.floatLayoutView.frame = CGRectMake(0 ,35, contentWidth, floatLayoutViewSize.height);

    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, 35 + floatLayoutViewSize.height);
    if (self.hotBlock) {
        self.hotBlock();
    }
}

#pragma mark - Target Methods

#pragma mark - Public Methods

#pragma mark - Private Method

#pragma mark - External Delegate

#pragma mark - Setter Getter Methods
- (UILabel *)hotLabel {
    if (!_hotLabel) {
        _hotLabel = [[UILabel alloc] init];
        _hotLabel.font = UIFontMake(13.f);
        _hotLabel.textColor = UIColorMakeWithHex(@"#999999");
        _hotLabel.text = @"热门搜索";
    }
    return _hotLabel;
}
- (QMUIFloatLayoutView *)floatLayoutView {
    if (!_floatLayoutView) {
        _floatLayoutView = [[QMUIFloatLayoutView alloc] init];
        _floatLayoutView.padding = UIEdgeInsetsMake(5, 10, 5, 10);
        _floatLayoutView.itemMargins = UIEdgeInsetsMake(0, 0, 10, 10);
        _floatLayoutView.minimumItemSize = CGSizeZero;
        _floatLayoutView.maximumItemSize = CGSizeMake(SCREEN_WIDTH - 30, 30);
        _floatLayoutView.centerFillLineView = false;
    }
    return _floatLayoutView;
}

@end
